//
// Created by DengLibin on 2018/12/13 0013.
//
/**
 * 容器stack: 栈
 */
#include <iostream>
#include <string>
#include <stack>
using namespace std;
/**
 * 容器stack: 栈
 */

class StackTeacher
{
public:

    int age;
    string name;
    StackTeacher(){}
    StackTeacher(const StackTeacher & stackTeacher){
        cout <<"StackTeacher拷贝构造函数"<<endl;
        this->age = stackTeacher.age;
        this->name = stackTeacher.name;
    }
    void print()
    {
        cout << "age = " << age << " name = " << name << endl;
    }
};
template<typename T>
void showStack(stack<T> &s)
{
    cout << "stack大小:" << s.size() << endl;
    //后进先出
    while (!s.empty())
    {
        T t = s.top();
        cout << t << ",";
        s.pop();//弹出栈顶元素
    }
}
void testStack()
{
    stack<int> s;
    //入栈
    for (int i = 0; i < 10; i++)
    {
        s.push(i);
    }
    showStack(s);
}
//存对象
void teacherStack()
{
    stack<StackTeacher> s;
    StackTeacher t1, t2, t3;
    t1.name = "张三";
    t1.age = 34;

    t2.name = "李四";
    t2.age = 32;

    t3.name = "王五";
    t3.age = 24;

    s.push(t1); //执行拷贝构造函数
    s.push(t2);
    s.push(t3);

    while (!(s.empty()))
    {
        s.top().print();
        s.top().name = "hello";
        s.pop();
    }
    cout <<"t1.name="<< t1.name<<endl;
}
//存指针
void pTeacherStack()
{
    stack<StackTeacher*> s;
    StackTeacher t1, t2, t3;
    t1.name = "张三";
    t1.age = 34;

    t2.name = "李四";
    t2.age = 32;

    t3.name = "王五";
    t3.age = 24;

    s.push(&t1);
    s.push(&t2);
    s.push(&t3);

    while (!(s.empty()))
    {
        s.top()->print();
        s.top()->name = "hello";
        s.pop();
    }
    cout <<"t1.name="<< t1.name<<endl;
    cout <<"t2.name="<< t2.name<<endl;
    cout <<"t3.name="<< t3.name<<endl;

}

int main24()
{
    //testStack();
   // teacherStack();
   pTeacherStack();
    return 0;
}
